import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Scanner;
import java.util.SortedSet;
import java.util.TreeMap;

public class Task4 {
	
	public static void main(String[] args) {
		
		Scanner inputCS = new Scanner(System.in);
		int n = inputCS.nextInt();
		String[] inputLines = new String[n];
		inputCS.nextLine();
		//String[][] lines = new String[n][3];
		List<List<String>> lines = new ArrayList<List<String>>();
		
		for (int i = 0; i < inputLines.length; i++) {
			
			inputLines[i] = inputCS.nextLine();
			lines.add(Arrays.asList(inputLines[i].split(" ")));
		}
		
		for (int i = 0; i < lines.size(); i++) {
			
			for (int j = i + 1; j < lines.size(); j++) {
				
				if (lines.get(i).get(0).equals(lines.get(j).get(0)) &&
						lines.get(i).get(2).equals(lines.get(j).get(2))) {
					
					String[] tempy = new String[3];
					tempy[0] = lines.get(i).get(0);
					tempy[2] = lines.get(i).get(2);
					int tmp = Integer.parseInt(lines.get(i).get(1)) +
							Integer.parseInt(lines.get(j).get(1));
					tempy[1] = Integer.toString(tmp);
					
					lines.remove(j);
					lines.set(i, Arrays.asList(tempy));
				}
			}
		}
		
		List<String> products = new ArrayList<String>();
		
		for (int i = 0; i < lines.size(); i++) {
			
			if (products.contains(lines.get(i).get(2)) == false) {
				
				products.add(lines.get(i).get(2));
			}
		}
		
		for (int i = 0; i < products.size(); i++) {
			
			System.out.print(products.get(i) + ":");
			StringBuilder tempo = new StringBuilder();
			Map<String, String> map = new HashMap<String, String>();
			
			for (int j = 0; j < lines.size(); j++) {
				
				if (lines.get(j).get(2).equals(products.get(i))) {
					
					map.put(lines.get(j).get(0), lines.get(j).get(1));
					//tempo.append(", " + lines.get(j).get(0) + " " + lines.get(j).get(1));
				}
			}
			
			Map<String, String> treeMap = new TreeMap<String, String>(map);
			
			for (Map.Entry entry : treeMap.entrySet()) {
				
				tempo.append(", " + entry.getKey() + " " + entry.getValue());
			}
			
			tempo.deleteCharAt(0);
			
			System.out.print(tempo.toString());
			
			System.out.println();
		}
		
		System.out.println();
	}
}